package cn.nexd.utils;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import cn.nexd.utils.framework.tools.Logger;

public class MainActivity extends AppCompatActivity implements IMainView {


    private MainPresenter presenter;

    private static final String TAG = "MainActivity";
    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        presenter = new MainPresenter(this, this);
        Logger.isDebug(true);
//        StorageManager manager = (StorageManager) getSystemService(Context.STORAGE_SERVICE);
//        StorageVolume volume = manager.getPrimaryStorageVolume();
//        Intent intent = volume.createAccessIntent(Environment.DIRECTORY_PICTURES);
//        startActivityForResult(intent, 20);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);


        if (resultCode == Activity.RESULT_OK) {
            this.getContentResolver().takePersistableUriPermission(data.getData(),
                    Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
//            updateDirectoryEntries(data.getData());
        }

    }


    @Override
    public void onActivityReenter(int resultCode, Intent data) {
        super.onActivityReenter(resultCode, data);
    }


    public void showToast(final String msg) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
            }
        });
    }

    public void gotoLogActivity(View view) {
//        Intent intent = new Intent(this, LogTestActivity.class);
//        startActivity(intent);
    }



    public void gotoPhoneActivity(View view) {
        startActivity(new Intent(this ,PhoneActivity.class));
    }



    public void fileActivity(View view) {
        startActivity(new Intent(this, FileActivity.class));
    }

    public void gotoSDCardActivity(View view) {
        startActivity(new Intent(this, SDCardActivity.class));
    }
}
